<extend name="Public:base"/>
<block name="leftcolumn">
   <div class="panel panel-info">
	   <div class="panel-heading">
	      <h3 class="panel-title">
	         放养记录
	      </h3>
	   </div>
	   <div class="panel-body">
	       <button class="btn btn-lg btn-primary"  data-toggle="modal" data-target="#addStockingModal">添加</button><br><br>
	   	<table class="table table-bordered table-striped col-sm-12" >
		     <thead>
		        <tr>
		           <th>放养批次</th>
		           <th>鱼苗</th>
	           <if condition = "$pool_data['pool_model'] eq '网箱'">
	           	   <th>网箱</th>
               </if>
		           <th>数量</th>
		           <th>规格</th>
		           <th>投苗时间</th>
		           <th>预计上市时间</th>
		           <th>备注</th>
		           <th>操作</th>
		        </tr>
		     </thead>
		     <tbody>
		     	<volist name="stocking" id="stocking">	
			        <tr>
			           <td>{$stocking.stocking_batch}</td>
			           <td>{$stocking.stocking_fry_id}</td>
			         <if condition = "$pool_data['pool_model'] eq '网箱'">  
			           <td>{$stocking.stocking_cage_id}</td>
			         </if>  
			           <td>{$stocking.stocking_number}</td>
			           <td>{$stocking.stocking_specifications}</td>
			           <td>{$stocking.stocking_start_time}</td>
			           <td>{$stocking.stocking_finish_time}</td>
			           <td>{$stocking.stocking_remark}</td>
		               <td><button class="btn btn-danger" data-toggle="modal" data-target="#modifyStockingModal" value="{$stocking.stocking_id}" onclick="stockingChange(this)">修改</button></td>
			        </tr>
			    </volist> 
			  
		     </tbody>
 		 </table>
	   </div>
	     <div class="panel-footer">
	     	<ul class="pagination">
			 {$page}
		    </ul>
	     </div>
	</div>
	<!-- stockingModal -->
<div class="modal fade" id="addStockingModal" tabindex="-1" role="dialog" 
   aria-labelledby="myModalLabel" aria-hidden="true">
		   <div class="modal-dialog">
		      <div class="modal-content">
		         <div class="modal-header">
		            <button type="button" class="close" 
		               data-dismiss="modal" aria-hidden="true">
		                  &times;
		            </button>
		            <h4 class="modal-title" id="myModalLabel">
		               新放养信息
		            </h4>
		         </div>
		         <div class="modal-body">
		            <form action="{:U('Home/Safe/addStocking')}" id="addStocking_form" role="form" method="post">
		            	<div class="form-group">
		            		<label for="">放养批次</label>
		            		<input type="text" class="form-control" value="" name="stocking_batch" >
		            	</div>
		            	<div class="form-group">
		            		<label for="">鱼苗</label>
		            		<select class="form-control" name="stocking_fry_id" >
		            			<option value="0">请选择鱼苗</option>
		            			<volist name="fry" id="fr">
		            				<option value="{$fr.fry_id}">{$fr.fry_name}</option>
		            			</volist>
		            		</select>
		            	</div>
                        <if condition = "$pool_data['pool_model'] eq '网箱'">
			            	<div class="form-group">
			            		<label for="">网箱</label>
				            		<select class="form-control" name="stocking_cage_id" >
				            			<option value="0">请选择网箱</option>
				            			<volist name="cage" id="ca">
				            				<option value="{$ca.cage_id}">{$ca.cage_rowname}</option>
				            			</volist>
				            		</select>
			            	    </else>
			            	</div> 
		            	</if>
		            	<div class="form-group">
		            		<label for="">数量</label>
		            		<input type="text" class="form-control" value="" name="stocking_number" >
		            	</div>
		            	<div class="form-group">
		            		<label for="">规格</label>
		            		<input type="text" class="form-control" value="" name="stocking_specifications" >
		            	</div>
		            	<div class="form-group">
		            		<label for="">投苗时间</label>
		            		<input type="text" class="form-control" value="" name="stocking_start_time" >
		            	</div>
		            	<div class="form-group">
		            		<label for="">预计上市时间</label>
		            		<input type="text" class="form-control" value="" name="stocking_finish_time" >
		            	</div>
		            	
		            	<div class="form-group">
		            		<label for="">备注</label>
		            	    <textarea class="form-control" value="" name="stocking_remark"></textarea>
		            	</div>
		            	<label class="control-label" for="input01" name="time">当前时间: {$time} </label>
		            </form>
		         </div>
		         <div class="modal-footer">
		            <button type="button" class="btn btn-default" 
		               data-dismiss="modal">关闭
		            </button>
		            <button type="button"  id="addStockingBtn" class="btn btn-primary">
		               提交
		            </button>
		         </div>
		      </div><!-- /.modal-content -->
		</div><!-- /.modal -->

</div>

<!-- ModifyfryModal -->
<div class="modal fade" id="modifyStockingModal" tabindex="-1" role="dialog" 
   aria-labelledby="myModalLabel" aria-hidden="true">
		   <div class="modal-dialog">
		      <div class="modal-content">
		         <div class="modal-header">
		            <button type="button" class="close" 
		               data-dismiss="modal" aria-hidden="true">
		                  &times;
		            </button>
		            <h4 class="modal-title" id="myModalLabel">
		               修改放养信息
		            </h4>
		         </div>
		         <div class="modal-body">
		            <form action="{:U('Home/Safe/modifyStocking')}" id="modifyStocking_form" role="form" method="post">
		            	<div class="form-group">
		            		<label for="">放养批次</label>
		            		<input type="text" class="form-control" value="" name="stocking_batch" id="stocking_batch">
		            	</div>
		            	
		            	<div class="form-group">
		            		<label for="">鱼苗</label>
		            		<select class="form-control" value=""name="stocking_fry_id" id="stocking_fry_id">
		            			<option value="0">请选择鱼苗</option>
		            			<volist name="fry" id="f">
		            				<option value="{$f.fry_id}">{$f.fry_name}</option>
		            			</volist>
		            		</select>
		            	</div>
		            	<if condition = "$pool_data['pool_model'] eq '网箱'">
			            	<div class="form-group">
			            		<label for="">网箱</label>
			            		<select class="form-control" value=""name="stocking_cage_id" id="stocking_cage_id">
			            			<option value="0">请选择网箱</option>
			            			<volist name="cage" id="c">
			            				<option value="{$c.cage_id}">{$c.cage_rowname}</option>
			            			</volist>
			            		</select>
			            	</div>
			            </if>
		            	<div class="form-group">
		            		<label for="">数量</label>
		            		<input type="text" class="form-control" value="" name="stocking_number" id="stocking_number">
		            	</div>
		            	<div class="form-group">
		            		<label for="">规格</label>
		            		<input type="text" class="form-control" value="" name="stocking_specifications" id="stocking_specifications">
		            	</div>
		            	<div class="form-group">
		            		<label for="">投苗时间</label>
		            		<input type="text" class="form-control" value="" name="stocking_start_time" id="stocking_start_time">
		            	</div>
		            	<div class="form-group">
		            		<label for="">预计上市时间</label>
		            		<input type="text" class="form-control" value="" name="stocking_finish_time" id="stocking_finish_time">
		            	</div>
		            	<div class="form-group">
		            		<label for="">备注</label>
		            		<textarea class="form-control" value="" name="stocking_remark" id="stocking_remark"> </textarea>
		            	</div>
		            	
		            	<label class="control-label" for="input01" name="time">当前时间: {$time} </label>
		                <div class="form-group hidden">
		            		<input type="text" class="form-control" value="" name="stocking_id" id="stocking_id" >
		            	</div>
		            </form>
		         </div>
		         <div class="modal-footer">
		            <button type="button" class="btn btn-default" 
		               data-dismiss="modal">关闭
		            </button>
		            <button type="button"  id="modifyStockingBtn" class="btn btn-primary">
		               提交修改
		            </button>
		         </div>
		      </div><!-- /.modal-content -->
		</div><!-- /.modal -->
</div>
</block>
<block name="rightcolumn"> 
  <h1><strong>养殖管理</strong></h1>
   	  <ul class="nav nav-pills nav-stacked">
   	  	<li><a href="{:U('Home/Safe/stocking')}">放养管理</a></li>
   	  	<li><a href="{:U('Home/Safe/feeding')}">投饲管理</a></li>
   	  	<li><a href="{:U('Home/Safe/patrol')}">巡塘管理</a></li>
   	  	<li class="active"><a href="{:U('Home/Safe/medicine')}">用药管理</a></li>
   	  	<li><a href="{:U('Home/Safe/ill')}">病害管理</a></li>
   	  	<li><a href="{:U('Home/Safe/indicators')}">养殖指标管理</a></li>
   	  	<li><a href="">自动获取数据采集指标</a></li>
   	  </ul>
</block>
<block name="script"> 
	<script>
	function stockingChange(obj) { 
	       
			var val = $(obj).attr('value');
	        var url = "{:U('Home/Safe/getChooseStocking/val/"+val+"')}";
	        $.get(url, function(data, status){

	        	$('#stocking_id').val(data['stocking_id']);
	        	$('#stocking_batch').val(data['stocking_batch']);
	        	// $('#stocking_fry_id').val(data['stocking_fry_id']);
	        	// $('#stocking_cage_id').val(data['stocking_cage_id']);
	        	$('#stocking_number').val(data['stocking_number']);
	        	$('#stocking_specifications').val(data['stocking_specifications']);
	        	$('#stocking_start_time').val(data['stocking_start_time']);
	        	$('#stocking_finish_time').val(data['stocking_finish_time']);
	        	$('#stocking_remark').val(data['stocking_remark']);
	        });
	}
	$(document).ready(function(){

	      $('#addStockingBtn').click(function(){
	             var action = $('#addStocking_form').attr('action');
	             var Formattr = $('#addStocking_form').serialize();
	             $.post(action, Formattr, function(data,status) {
	                 if(status == "success") {
	                    alert( "添加成功！");
	                 }else{
	                 	alert("添加失败！");
	                 }
	                 setTimeout("window.location.href=\"{:U('Home/Safe/stocking')}\"",200);
	             });
	        });
	      $('#modifyStockingBtn').click(function(){

	        	 var action= $('#modifyStocking_form').attr('action');
	        	 var Formattr=$('#modifyStocking_form').serialize();
		         console.log(Formattr);
	             $.post(action, Formattr,function(data,status) {
	                 
	                 if(status == "success") {
	                    alert( "修改成功！");
	                 }else{
	                 	alert("修改失败！");
	                 }
	                 setTimeout("window.location.href=\"{:U('Home/Safe/stocking')}\"",200);
	             });
	        });
	});
	</script>
</block>